import { EventsModule } from './IM/events.module';
import { UploadModule } from './modules/upload/upload.module';
import { UserModule } from './modules/user/user.module';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { APP_FILTER } from '@nestjs/core';
import { HttpExceptionFilter } from './config';
import { AppService } from './app.service';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';
import { config } from './config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { CarBrandModule } from './modules/car_brand/car_brand.module';
import { CarModelModule } from './modules/car_model/car_model.module';
import { CarInfoModule } from './modules/car_info/car_info.module';
import { OrderModule } from './modules/order/order.module';

@Module({
  imports: [
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'dist/' + config.uploadPath),
      serveRoot: '/' + config.uploadPath,
    }),
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: config.mysql.host,
      port: config.mysql.port,
      username: config.mysql.username,
      password: config.mysql.password,
      database: config.mysql.database,
      synchronize: false,
      autoLoadEntities: true,
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
    }),
    UserModule,
    UploadModule,
    EventsModule,
    CarBrandModule,
    CarModelModule,
    CarInfoModule,
    OrderModule,
  ],
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilter,
    },
  ],
})
export class AppModule {}
